import axios from "axios";
import Axios from "axios";

export const httpInstance = axios.create();


//设置请求根路径
// httpInstance.defaults.baseURL = import.meta.env.CHUANLIN_BASEURL;
httpInstance.defaults.baseURL = "/api";


// 创建axios
const service = Axios.create({
    baseURL: httpInstance.defaults.baseURL,
    withCredentials: true,
});

service.interceptors.request.use(
    (config) => {
        const authorization = localStorage.getItem("Authorization");
        config.headers["Authorization"] = authorization;
        return config;
    },
    (error) => {
        return Promise.reject(error);
    },
);

service.interceptors.response.use(
    (response) => {
        const res = response.data
        // if (res.code == 200) {
        //     return res;
        // } else if (res.code == 603) {
        //     // code为603代表token已经失效,
        //     // 提示用户,然后跳转到登陆页面
        //     router.push('/login')
        // } else {
        //     Promise.reject(res.msg);
        // }
        return res;
    },
    (error) => {
        return Promise.reject(error);
    },
);

export default service;


